import request from '@/utils/request'

// api地址
const api = {
  list: '/v1/address/list',
  defaultId: '/v1/address/getDefault',
  detail: '/v1/address/get',
  add: '/v1/address/update',
  edit: '/v1/address/update',
  setDefault: '/v1/address/setDefault',
  remove: '/v1/address/delete'
}

// 收货地址列表
export const list = (param) => {
  return request.get(api.list, param)
}

// 默认收货地址ID
export const defaultId = (param) => {
  return request.get(api.defaultId, param)
}

// 收货地址详情
export const detail = (address_id) => {
  return request.get(api.detail, { address_id })
}

// 新增收货地址
export const add = (data) => {
  return request.post(api.add, { name: data.name, mobile:data.phone, region:data.region, street:data.detail })
}

// 编辑收货地址
export const edit = (addressId, data) => {
  return request.post(api.edit, { address_id: addressId, name: data.name, mobile:data.phone, region:data.region, street:data.detail })
}

// 设置默认收货地址
export const setDefault = (address_id) => {
  return request.post(api.setDefault, { address_id })
}

// 删除收货地址
export const remove = (address_id) => {
  return request.post(api.remove, { address_id })
}
